const express=require('express')
const pool=require('../pool')
const  router=express.Router()

// 商品信息
router.get('/laptop',(req,res,next)=>{
  let sql='select title,newprice,smpic from sm_laptop where family_id=21'
  //  let sql='select sm_laptop.title,sm_laptop.newprice,sm_laptop_pic.sm from sm_laptop,sm_laptop_pic where sm_laptop_pic.laptop_id=sm_laptop.family_id=7'
  //  select sm_laptop.title,sm_laptop.newprice,sm_laptop_pic.sm from sm_laptop,sm_laptop_pic where sm_laptop_pic.laptop_id=sm_laptop.lid;
  pool.query(sql,(err,result)=>{
    if(err){next(err);return}
    res.send({
      code:1,
      msg:"数据返回成功",
      data:result
    })
  })
  // (select * from sm_laptop left outer join sm_laptop_pic on laptop_id=lid)
  // union
  // (select * from sm_laptop right outer join sm_laptop_pic on laptop_id=lid);
  // select sm_laptop.title,sm_laptop.newprice from sm_laptop,sm_laptop_pic where laptop_id=lid;
  // select title,newprice from sm_laptop inner join sm_laptop_pic on laptop_id=lid;
})
// 首页
router.get("/laptap", (req, res, next) => {
    let sql = "select * from sm_index_carousel"
    pool.query(sql, (err, data) => {
      if (err) {
        next(err)
        return
      }
      res.send({
        code: 1,
        msg: "数据返回成功",
        data: data,
      })
    })
  })
  //首页遍历图片
  router.get("/index_laptap", (req, res, next) => {
    let sql = "select * from index_sm_laptop_family"
    pool.query(sql, (err, data) => {
      if (err) {
        next(err)
        return
      }
      res.send({
        code: 1,
        msg: "数据返回成功",
        data: data,
      })
    })
  })

module.exports=router